package 最小正和子数组.src;

import java.util.List;

public class Solution {
    public int minimumSumSubarray(List<Integer> nums, int l, int r) {
        // Example implementation
        int minSum = Integer.MAX_VALUE;
        int currentSum = 0;
        int left = 0;

        for (int right = 0; right < nums.size(); right++) {
            currentSum += nums.get(right);

            while (right - left + 1 >= l && currentSum > 0) {
                if (right - left + 1 <= r) {
                    minSum = Math.min(minSum, currentSum);
                }
                currentSum -= nums.get(left++);
            }
        }

        return minSum == Integer.MAX_VALUE ? -1 : minSum;
    }


}